import { Message, MessageBox } from 'element-ui'
import { deleteData } from 'api/getData'
export const deleteConfim = (that, title, id, fn) => {
    const h = that.$createElement
    MessageBox(
        {
            title: '确定删除',
            message: h('p', null, [
                h('span', null, '删除 '),
                h('span', { style: 'color: teal' }, title)
            ]),
            showCancelButton: true,
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            beforeClose: (action, instance, done) => {
                if (action === 'confirm') {
                    instance.confirmButtonLoading = true
                    instance.confirmButtonText = '删除中...'
                    console.log('调用删除接口' + id)
                    deleteData(id).then((res) => {
                        done()
                        setTimeout(() => {
                            instance.confirmButtonLoading = false
                        }, 300)
                    }).catch((err) => {
                        setTimeout(() => {
                            instance.confirmButtonLoading = false
                            instance.confirmButtonText = '确定'
                        }, 300)
                        console.log(err)
                    })
                } else {
                    done()
                }
            }
        }
    ).then(() => {
        // console.log('清空' + dataArr)
        if (typeof fn === 'function') {
            fn(that.currentPage, that.input)
        } else if (that.tableData) {
            that.tableData = []
        }
    }).catch(() => {
        Message({
            type: 'info',
            message: '已取消删除'
        })
    })
}